package com.offics.loan.interfaces.controller;

import com.offics.loan.application.dto.faq.FAQResponse;
import com.offics.loan.application.service.FAQApplicationService;
import com.offics.loan.infrastructure.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * FAQ控制器
 */
@Tag(name = "常见问题", description = "常见问题相关接口")
@RestController
@RequestMapping("/api/faq")
@RequiredArgsConstructor
public class FAQController {

    private final FAQApplicationService faqApplicationService;

    /**
     * 获取所有启用的FAQ列表
     *
     * @return FAQ列表
     */
    @Operation(summary = "获取所有FAQ", description = "获取所有启用的FAQ列表")
    @GetMapping
    public Result<List<FAQResponse>> getAllFAQs() {
        List<FAQResponse> faqs = faqApplicationService.getAllEnabledFAQs();
        return Result.success(faqs);
    }

    /**
     * 根据分类获取FAQ列表
     *
     * @param category 分类（0-贷款，1-还款，2-账户，3-其他）
     * @return FAQ列表
     */
    @Operation(summary = "根据分类获取FAQ", description = "根据分类获取启用的FAQ列表")
    @GetMapping("/category/{category}")
    public Result<List<FAQResponse>> getFAQsByCategory(
            @Parameter(description = "分类（0-贷款，1-还款，2-账户，3-其他）") 
            @PathVariable Integer category) {
        List<FAQResponse> faqs = faqApplicationService.getFAQsByCategory(category);
        return Result.success(faqs);
    }

    /**
     * 根据ID获取FAQ详情
     *
     * @param id FAQ ID
     * @return FAQ详情
     */
    @Operation(summary = "获取FAQ详情", description = "根据ID获取FAQ详情")
    @GetMapping("/{id}")
    public Result<FAQResponse> getFAQById(
            @Parameter(description = "FAQ ID") 
            @PathVariable Long id) {
        FAQResponse faq = faqApplicationService.getFAQById(id);
        return Result.success(faq);
    }
}